﻿<Page
    x:Name="pageRoot"
    x:Class="TileExplorer.ItemDetailPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TileExplorer"
    xmlns:common="using:TileExplorer.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:dataModel="using:TileExplorer.DataModel"
    mc:Ignorable="d">
    
    <Page.Resources>
        <CollectionViewSource
            x:Name="itemsViewSource"
            Source="{Binding Items}"
            d:Source="{Binding AllGroups[0].Items, Source={d:DesignInstance Type=dataModel:DataSource, IsDesignTimeCreatable=True}}"/>
    </Page.Resources>
    
    <Page.BottomAppBar>
        <CommandBar>
            <CommandBar.PrimaryCommands>
                <AppBarButton Icon="Home" Label="Home" Click="HomeCommand_OnClick"></AppBarButton>
                <AppBarButton Icon="Play" Loaded="NotificationButton_OnLoaded" Click="NotificationCommand_OnClick"></AppBarButton>
            </CommandBar.PrimaryCommands>
            <CommandBar.SecondaryCommands>
                <AppBarButton Icon="Copy" Label="Copy" Click="CopyCommand_OnClick"></AppBarButton>
                <AppBarButton Icon="Accept" Label="Set" Click="SetCommand_OnClick"></AppBarButton>
                <AppBarButton Icon="Pin" Label="Pin" Click="PinCommand_OnClick"></AppBarButton>
            </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
        DataContext="{Binding Group}"
        d:DataContext="{Binding AllGroups[0], Source={d:DesignData Type=dataModel:DataSource, IsDesignTimeCreatable=True}}">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--
            TODO: Content should be placed within the following grid 
                  to show details for the current item
        -->
        <Grid Grid.Row="1" x:Name="contentRegion">
            <FlipView 
                x:Name="flipView"
                TabIndex="1"
                Grid.RowSpan="2"
                ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
                VerticalAlignment="Top"
                VerticalContentAlignment="Top">
                <FlipView.ItemContainerStyle>
                    <Style TargetType="FlipViewItem">
                        <Setter Property="Margin" Value="0,37,0,0"/>
                    </Style>
                </FlipView.ItemContainerStyle>
                <FlipView.ItemTemplate>
                    <DataTemplate>
                        <ScrollViewer x:Name="scrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                            <Grid x:Name="FullItem" HorizontalAlignment="Center" VerticalAlignment="Top">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="350"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Image VerticalAlignment="Top"
                                       Width="{Binding Converter={StaticResource TileSizer}, ConverterParameter='w'}"
                                       Height="{Binding Converter={StaticResource TileSizer}, ConverterParameter='h'}"
                                       Source="{Binding Converter={StaticResource TileConverter}}"/>
                                <StackPanel Orientation="Vertical" Grid.Column="1">
                                    <TextBlock Text="{Binding Id}" Style="{StaticResource HeaderTextBlockStyle}" FontSize="30"/>
                                    <TextBlock Text="{Binding Description}" Style="{StaticResource CaptionTextBlockStyle}" Margin="0 10 0 0"/>
                                    <TextBlock Text="{Binding Xml}" TextWrapping="Wrap" Style="{StaticResource BaseTextBlockStyle}" Margin="0 10 0 0"></TextBlock>
                                </StackPanel>
                            </Grid>
                        </ScrollViewer>
                    </DataTemplate>                    
                </FlipView.ItemTemplate>
            </FlipView>
        </Grid>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
                        Style="{StaticResource NavigationBackButtonNormalStyle}"
                        VerticalAlignment="Top"
                        AutomationProperties.Name="Back"
                        AutomationProperties.AutomationId="BackButton"
                        AutomationProperties.ItemType="Navigation Button"/>
            <TextBlock x:Name="pageTitle" Text="{Binding Name}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                        IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
        </Grid>
    </Grid>
</Page>
